package lzk.myshop.dao;


import lzk.myshop.Util.NewGoods;
import lzk.myshop.pojo.Goods;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface GoodsMapper{

    @Select("select * from goods where `id` = #{id}")
    Goods getGoodsByid(int id);

    @Select("select* from goods where `status`=1")
    List<Goods> allGoods();

    @Select("SELECT * FROM goods WHERE `name` LIKE CONCAT('%', #{name}, '%') and `status`=1")
    List<Goods> searchGoodsByName(String name);

    @Select("select `price` from `goods` where `id` = #{goodsid}")
    double getPrice(int goodsid);

    @Select("select `name` from `goods` where `id` = #{id}")
    String getGoodsNameByID(int id);

    @Select("select * from goods where `merchantid` =#{merchantid} and `status`= 1")
    List<Goods> goodsOfMer(int merchantid);

    @Select("select `merchantid` from `goods` where `id`=#{id}")
    int getMerIDByGoodsID(int id);

    @Insert("insert into `goods` (`merchantid`,`classifyname`,`name`,`introduce`,`price`,`quantity`,`image`) values (#{merchantid}, #{classifyname}, #{name}, #{introduce}, #{price}, #{quantity}, #{image})")
    int addGoods(Goods goods);

    @Update("UPDATE goods SET `classifyname` = #{classifyname}, `name` = #{name}, `introduce` = #{introduce}, `price` = #{price}, `quantity` = #{quantity}, `image` = #{image} WHERE `id` = #{id}")
    int alterGoods(Goods goods);

    @Update("update goods set `status`= 0 where `id` = #{id}")
    int downGoods(int id);

    @Update("UPDATE `goods` SET `quantity` = #{count} - #{value} WHERE id = #{id}")
    int reduce(int count,int id);

    @Update("update `goods` set `image` = #{image} where `id`=#{id}")
    int addImage(String image,int id);
    @Insert("insert into `goods` (`merchantid`,`classifyname`,`name`,`introduce`,`price`,`quantity`,`image`) values (#{merchantid}, #{classifyname}, #{name}, #{introduce}, #{price}, #{quantity}, #{image})")
    int newGoods(NewGoods newGoods);
}
